<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <link href="../css/element.css" rel="stylesheet"/>
    <link href="../css/styleindex.css" rel="stylesheet"/>
    <style>

    </style>
</head>
<body style="background:#EFF0F4;">

  <div class="mui-content">
    <div id="vm" class="x-examok" v-cloak>
      <div class="x-header-g" id="header">
        <a class="x-header-arrow" @click="api.closeWin()"></a>
        <div class="x-header-t">添加临时采购</div>
      </div>
      <!--  -->
      <div class="x-addmate">

      <el-form ref="form" :model="form" label-width="100px" :rules="rules">
        <el-form-item label="名称" prop="title">
          <el-input v-model="form.title" clearable placeholder="请输入"></el-input>
        </el-form-item>
        <el-form-item label="分类" prop="cate" >
          <el-select v-model="form.cate" placeholder="请选择">
            <el-option
              v-for="item in catedata"
              :key="item.id"
              :label="item.title"
              :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="购规格" prop="buyunit">
          <el-input v-model="form.buyunit" clearable placeholder="箱/盒/袋/桶/瓶/斤"></el-input>
        </el-form-item>
        <el-form-item label="存规格" prop="saveunit">
          <el-input v-model="form.saveunit" clearable placeholder="箱/盒/袋/桶/瓶/斤"></el-input>
        </el-form-item>
        <el-form-item label="存系数" prop="savenum">
          <el-input v-model="form.savenum" clearable placeholder="请输入" type="number"></el-input>
        </el-form-item>
        <el-form-item label="产规格" prop="takebuy">
          <el-input v-model="form.takebuy" clearable placeholder="箱/盒/袋/桶/瓶/斤/克/毫升"></el-input>
        </el-form-item>
        <el-form-item label="产系数" prop="takenum">
          <el-input v-model="form.takenum" clearable placeholder="请输入" type="number"></el-input>
        </el-form-item>
        <el-form-item label="管理方式" prop="admintype">
          <el-radio-group v-model="form.admintype">
            <el-radio :label="item.id" v-for="(item,index) in admintypedata">{{item.title}}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="盘点方式" prop="gettype">
          <el-radio-group v-model="form.gettype">
            <el-radio :label="item.id" v-for="(item,index) in gettypedata">{{item.title}}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="是否计算出成" prop="isgetnum">
          <el-radio-group v-model="form.isgetnum">
            <el-radio :label="item.id" v-for="(item,index) in isgetnumdata">{{item.title}}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="初始出成率" prop="startnum">
          <el-input v-model="form.startnum" clearable placeholder="请输入" type="number"></el-input>
        </el-form-item>
        <el-form-item label="供应商" prop="supplier" >
          <el-select v-model="form.supplier" placeholder="请选择">
            <el-option
              v-for="item in supplierdata"
              :key="item.id"
              :label="item.title"
              :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>

      </el-form>
      </div>
      <!--  -->
      <div class="x-pro-gobtn" @click="isokget">提交</div>
    </div>
  </div>

  <script type="text/javascript" src="../script/vue.js"></script>
  <script type="text/javascript" src="../script/element.js"></script>
  <script type="text/javascript" src="../script/api.js"></script>
  <script type="text/javascript" src="../script/base.js"></script>
	<script>
apiready = function () {
    $api.fixStatusBar($api.byId('header'));


    //
    var vm = new Vue({
      el:'#vm',
      data(){
        return{
          form:{
            title:'',
            cate:'',
            buyunit:'',
            saveunit:'',
            savenum:'',
            takebuy:'',
            takenum:'',
            startnum:'',
            admintype:'',
            gettype:'',
            isgetnum:'',
            startnum:'',
            supplier:'',
          },
          rules:{
            title:[
              {required:true,message:'请输入名称',trigger:'blur'}
            ],
            cate: [
              { required: true, message: '请选择', trigger: 'change' }
            ],
            buyunit: [
              { required: true, message: '请输入', trigger: 'blur' }
            ],
            saveunit:[
              { required: true, message: '请输入', trigger: 'blur' }
            ],
            savenum:[
              { required: true, message: '请输入', trigger: 'blur' }
            ],
            takebuy:[
              { required: true, message: '请输入', trigger: 'blur' }
            ],
            takenum:[
              { required: true, message: '请输入', trigger: 'blur' }
            ],
            startnum:[
              { required: true, message: '请输入', trigger: 'blur' }
            ],
            admintype:[
              { required: true, message: '请选择', trigger: 'change' }
            ],
            gettype:[
              { required: true, message: '请选择', trigger: 'change' }
            ],
            isgetnum:[
              { required: true, message: '请选择', trigger: 'change' }
            ],
            startnum:[
              { required: true, message: '请输入', trigger: 'blur' }
            ],
            supplier:[
              { required: true, message: '请选择', trigger: 'change' }
            ]

          },
          catedata:'',
          buyunitdata:[{
          title:'箱',
          id:'1'
          },{
            title:'盒',
            id:'2'
          },{
            title:'袋',
            id:'3'
          },{
            title:'桶',
            id:'4'
          },{
            title:'瓶',
            id:'5'
          },{
            title:'斤',
            id:'6'
          }],
          admintypedata:[{
            title:'库房',
            id:'1'
          },{
            title:'直拨',
            id:'2'
          }],
          gettypedata:[{
            title:'日盘',
            id:'1'
          },{
            title:'旬盘',
            id:'2'
          }],
          isgetnumdata:[{
            title:'是',
            id:'1'
          },{
            title:'否',
            id:'2'
          }],
          supplierdata:'',//供应商
          isclick:true,

        }
      },
      created:function() {
        var that=this;


      },
      mounted:function(){
        var that=this;
        that.getcatedata()
        that.getsupplierdata()

      },
      methods: {
        //提交
        isokget:function(){
          let that=this;
          if(that.isclick){
            that.isclick = false
            api.ajax({
              url:baseurl+'api/material/addInfo',
              methods:'get',
              data:{
                values:{
                  sec: $api.getStorage('apptoken'),
                  title:this.form.title,
                  cateid:this.form.cate,
                  buy_unit:this.form.buyunit,
                  save_unit:this.form.saveunit,
                  save_ratio:this.form.savenum,
                  produce_unit:this.form.takebuy,
                  produce_ratio:this.form.takenum,
                  manager_unit:this.form.admintype,
                  check_unit:this.form.gettype,
                  is_count:this.form.isgetnum,
                  count_rate:this.form.startnum,
                  supplierid:this.form.supplier,
                }
              }
            },function(ret,err){
              if(ret){
                api.hideProgress();
                console.log(JSON.stringify(ret));
                if(ret.status == 1){
                  api.toast({
                      msg: ret.msg,
                      duration: 3000,
                      location: 'bottom'
                  });
                  api.sendEvent({
                      name: 'addmaterialok',
                      extra: {
                          
                      }
                  });
                  setTimeout(function(){
                    api.closeWin()
                  },1500)
                }else{
                  api.toast({
                      msg: ret.msg,
                      duration: 3000,
                      location: 'bottom'
                  });
                }
              }else{
                api.hideProgress();
                console.log(JSON.stringify(err));
                api.toast({
                    msg: err.msg,
                    duration: 3000,
                    location: 'bottom'
                });
              }
            })
          }
          
        },
        //供应商
        getsupplierdata:function(){
          let that=this;
          api.ajax({
            url:baseurl+'api/material/supplier',
            methods:'get',
            data:{
              values:{
                sec: $api.getStorage('apptoken'),
                type:'1'
              }
            }
          },function(ret,err){
            if(ret){
              api.hideProgress();
              console.log(JSON.stringify(ret));
              if(ret.status == 1){
                that.supplierdata = ret.data;
              }else{
                api.toast({
                    msg: ret.msg,
                    duration: 3000,
                    location: 'bottom'
                });
              }
            }else{
              api.hideProgress();
              console.log(JSON.stringify(err));
              api.toast({
                  msg: err.msg,
                  duration: 3000,
                  location: 'bottom'
              });
            }
          })
        },
        //分类
        getcatedata:function(){
          let that=this;
          api.ajax({
            url:baseurl+'api/material/cateList',
            methods:'get',
            data:{
              values:{
                sec: $api.getStorage('apptoken')
              }
            }
          },function(ret,err){
            if(ret){
              api.hideProgress();
              console.log(JSON.stringify(ret));
              if(ret.status == 1){
                that.catedata = ret.data.list;
              }else{
                api.toast({
                    msg: ret.msg,
                    duration: 3000,
                    location: 'bottom'
                });
              }
            }else{
              api.hideProgress();
              console.log(JSON.stringify(err));
              api.toast({
                  msg: err.msg,
                  duration: 3000,
                  location: 'bottom'
              });
            }
          })
        },
      }
    })
	}


	</script>
</body>
</html>
